layui.use(['jquery', 'common', 'layer', 'element'], function() {
	var $ = layui.jquery,
		layer = layui.layer,
		common = layui.common,
		element = layui.element;

	
	
	$('#shortcut section.panel').on('click', function() {
		var title = $(this).children('.right-value').find('h3').text();
		var href = $(this).children('.right-value').find('a').data('href');
		var icon = $(this).children('larry-ico').children('i').text();
		var data = {
			title: title,
			href: href,
			icon: icon
		}
		top.larryTab.tabAdd(data);
	});
    
	$('.larry-panel .tools').on('click',function(){
           if($(this).hasClass('down')){
               $(this).addClass('up').removeClass('down');
               $(this).children('i').remove();
               $(this).append('<i class="larry-icon">&#xe9eb;</i>');
               $(this).parent('.larry-panel-header').siblings('.larry-panel-body').slideToggle();
           }else{
               $(this).addClass('down').removeClass('up');
               $(this).children('i').remove();
               $(this).append('<i class="larry-icon">&#xe93a;</i>');
               $(this).parent('.larry-panel-header').siblings('.larry-panel-body').slideToggle();
           }
	});

	common.larryCmsLoadJq('http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js', function() {
		var dom = document.getElementById("larry_counts");
		var myChart = echarts.init(dom);
		var app = {};
		option1 = null;
		option1 = {
		    tooltip : {
		        formatter: "{a} <br/>{b} : {c}%"
		    },
		    toolbox: {
		        feature: {
		            restore: {},
		            saveAsImage: {}
		        }
		    },
		    series: [
		        {
		            name: 'cpu使用率',
		            type: 'gauge',
		            detail: {formatter:'{value}%'},
		            data: [{value: 0, name: 'cpu使用率'}]
		        }
		    ]
		};
		setInterval(function () {
			
			$.post("/Cpu",{},function (res){
				 option1.series[0].data[0].value = res.data;
				    myChart.setOption(option1, true);
			})
		},2000);
		if (option1 && typeof option === "object") {
		    myChart.setOption(option1, true);
		}
		
		
		var dom1 = document.getElementById("larry_counts1");
		var myChart1 = echarts.init(dom1);
		var app = {};
		option = null;
		option = {
		    tooltip : {
		        formatter: "{a} <br/>{b} : {c}%"
		    },
		    toolbox: {
		        feature: {
		            restore: {},
		            saveAsImage: {}
		        }
		    },
		    series: [
		        {
		            name: '内存使用率',
		            type: 'gauge',
		            detail: {formatter:'{value}%'},
		            data: [{value: 0, name: '内存使用率'}]
		        }
		    ]
		};
		setInterval(function () {
			$.post("/Memory",{},function (res){
				 option.series[0].data[0].value = res.data.Percentage;
				 myChart1.setOption(option, true);
			})
		},2000);
		if (option && typeof option === "object") {
		    myChart1.setOption(option, true);
		}
		
		
	});
	
});